<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of form_act_users_controller
 *
 * @author fredy
 */
class FormActUsersController extends AppController {

    //put your code here
    var $name = "FormActUsers";

    function index($form_act_id) {
        $this->layout = "ajax";
        $this->FormActUser->recursive = 1;
        $this->set('panelistas', $this->FormActUser->find("all", array(
                    'conditions' => array('FormActUser.form_act_id' => $form_act_id),
                    'fields' => array('FormActUser.id', 'FormActUser.rol', 'FormActUser.user_id', 'User.nombre', 'User.primer_apellido', 'User.segundo_apellido'),
                    'order' => array('User.primer_apellido ASC'))));
        $this->set('form_act_id', $form_act_id);
    }

    function add($form_act_id) {
        $this->layout = "ajax";
        if (!empty($this->data)) {
            if ($this->FormActUser->saveAll($this->data)) {
                $this->Session->setFlash(_("Panelista agregado con éxito"));
                $this->redirect(array('controller' => 'FormActUsers', 'action' => 'index', $form_act_id));
            }
        } else {
            //envio el id del acta a la que pertenece
            $this->set('form_act_id', $form_act_id);
            //envio el listado de los panelistas.
            $this->set('usuarios', $this->FormActUser->User->find('list', array(
                        'conditions' => array('User.group_id' => '29'),
                        'fields' => array('User.id', 'User.nombre_completo'))));
        }
    }

    function delete($id, $form_act_id) {
        if ($this->FormActUser->delete($id)) {
            $this->Session->setFlash(_("Panelista eliminado del acta"));
            $this->redirect(array('controller' => 'FormActUsers', 'action' => 'index', $form_act_id));
        }
    }

}

?>
